const {
  getNbThingOptions,
  createNbThingOption,
  updateNbThingOption,
  getNbThingOption,
} = require("@/models/v1/nb-thing-option-model");

exports.list = async (req, res, next) => {
  try {
    const result = await getNbThingOptions();
    res.backSuccess(result);
  } catch (error) {
    next(error);
  }
};

exports.create = async (req, res, next) => {
  try {
    const bodyParams = req.body;
    const top = await getNbThingOption({ title: bodyParams.title });
    if (top) throw new Error("事件已存在");
    const result = await createNbThingOption(bodyParams);
    res.backSuccess(result);
  } catch (error) {
    next(error);
  }
};

exports.update = async (req, res, next) => {
  try {
    const { id } = req.params;
    const bodyParams = req.body;
    const result = await updateNbThingOption(id, bodyParams);
    res.backSuccess(result);
  } catch (error) {
    next(error);
  }
};

exports.detail = async (req, res, next) => {
  try {
    const result = await getNbThingOption({ id: req.params.id });
    res.backSuccess(result);
  } catch (error) {
    next(error);
  }
};
